package module

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2010-11-20
 * Time: 12:49:07
 * To change this template use File | Settings | File Templates.
 */
class ICBCMainPageModule extends BankMainPageModule {

  ICBCMainPageModule(def buffer) {
    super(buffer)
  }

  public void defineUi() {
    ui.Container(uid: "Table", clocator: [tag: "table"]) {
      Selector(uid: "provinceSelector", clocator: [tag: "select", id: "selectSiteArea1695591979"])
      InputBox(uid: "searchBtn", clocator: [tag: "input", type: "button", value: "查询", id: "btnSearch1695591979"], respond: ["click"])
    }
    ui.Table(uid: 'dataTable', clocator: [class: 'tableDataTableAsset'])
    ui.Frame(uid: "myframe", clocator: [id: 'C-2131878364'])
    ui.Container(uid: 'pager', clocator: [class: 'tdCommonTablePage']) {
    }
    ui.InputBox(uid: 'page', clocator: [name: 'pageNETSITE'])
    ui.Button(uid: 'gopage', clocator: [name: 'gopage', class: 'SMALLBTN_IMG_OK'])
    ui.UrlLink(uid: "nextPage", clocator: [text: "下一页"])
  }

  public def getAllProvinceNames() {
    getSelectOptions('Table.provinceSelector')[1..-1]
  }

  public selectProvince(provinceName) {
    select('Table.provinceSelector', provinceName)
    click 'Table.searchBtn'
    waitForPageToLoad 1000000
    waitForFrameToLoad('myframe', 100000)
    selectFrameByIndex(0)
    //println "--------------------${provinceName}----------------------"
    def source = getSource()
    buffer.produce "<root>" + source + "</root>"

    def pagerInfo = getText('pager')
    //println new String(pagerInfo.getBytes('UTF-8'),'UTF-8')
    pagerInfo = pagerInfo.replace("首 页 │ 上一页 │ 下一页 │ 末 页    共 ", "").replace(" 页  第 1 页  至   页", "")//哥水平太高了
    (Integer.valueOf(pagerInfo) - 1).times {
      click 'nextPage'
      waitForPageToLoad 1000000
      waitForFrameToLoad('myframe', 100000)
      //selectFrameByIndex(0)

      //def before = """<link rel="stylesheet" type="text/css" href="\\icbc\\Optimize\\res\\common.css" dir="rtl">"""
      println this.getHtmlSource()
      source = getSource()

      buffer.produce "<root>" + source + "</root>"
    }
    selectMainWindow()
  }
}
